package com.countertack.dynamicinstrumentation;

import com.countertack.ssh.SSHManager;
import com.countertack.utils.Configuration;
import com.countertack.utils.HttpClientUtils;
import com.countertack.utils.Utils;
import com.countertack.vmware.VMWareConnector;
import com.countertack.vmware.VMWareUtils;
import com.vmware.vim25.Description;
import com.vmware.vim25.DynamicProperty;
import com.vmware.vim25.GuestNicInfo;
import com.vmware.vim25.OptionValue;
import com.vmware.vim25.VirtualDevice;
import com.vmware.vim25.VirtualMachineFlagInfo;
import com.vmware.vim25.mo.VirtualMachine;

public class Test {
	public static void main1(String[] args) {
		String configFilePath = "config.properties";

		Configuration.loadProperties(configFilePath);
		// SSHManager sshmngr=new SSHManager("root", "f00b@r",
		// "10.150.100.243");
		//
		// sshmngr.connect();
		//
		// sshmngr.downloadFile("/var/log/flume-ng/flume-cmf-flume1-AGENT-s13.dev.countertack.com.log",
		// "flume-cmf-flume1-AGENT-s13.dev.countertack.com.log");
		// System.out.println("completed");

		String payloadregCond = "{\"type\":\"condition\",\"isNew\":true,\"is_user_visible\":true,\"is_user_editable\":true,\"is_validated_xml\":true,\"xml_string\":\"<?xml version=\\\"1.0\\\"?><cybox:Observables xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\" xmlns:cybox=\\\"http://cybox.mitre.org/cybox-2\\\" xmlns:cyboxCommon=\\\"http://cybox.mitre.org/common-2\\\" xmlns:AddrObj=\\\"http://cybox.mitre.org/objects#AddressObject-2\\\" xmlns:URIObj=\\\"http://cybox.mitre.org/objects#URIObject-2\\\" xmlns:FileObj=\\\"http://cybox.mitre.org/objects#FileObject-2\\\" xmlns:EmailMessageObj=\\\"http://cybox.mitre.org/objects#EmailMessageObject-2\\\" xmlns:cyboxVocabs=\\\"http://cybox.mitre.org/default_vocabularies-2\\\" xmlns:example=\\\"http://example.com/\\\" xsi:schemaLocation=\\\"http://cybox.mitre.org/cybox-2 http://cybox.mitre.org/XMLSchema/core/2.0.1/cybox_core.xsd     http://cybox.mitre.org/objects#URIObject-2 http://cybox.mitre.org/XMLSchema/objects/URI/2.0.1/URI_Object.xsd     http://cybox.mitre.org/objects#FileObject-2 http://cybox.mitre.org/XMLSchema/objects/File/2.0.1/File_Object.xsd     http://cybox.mitre.org/objects#EmailMessageObject-2 http://cybox.mitre.org/XMLSchema/objects/Email_Message/2.0.1/Email_Message_Object.xsd     http://cybox.mitre.org/default_vocabularies-2 http://cybox.mitre.org/XMLSchema/default_vocabularies/2.0.1/cybox_default_vocabularies.xsd   \\\" cybox_major_version=\\\"2\\\" cybox_minor_version=\\\"0\\\" cybox_update_version=\\\"1\\\"><cybox:Observable id=\\\"Rosapa:RegWrite-a585919c-1d07-4d5d-a781-0e58dd56d9f1\\\" xmlns:cybox=\\\"http://cybox.mitre.org/cybox-2\\\"><cybox:Title>Rosapa Registry Write Condition</cybox:Title><cybox:Description>This observable detects any write to registry key  </cybox:Description><cybox:Keywords><cybox:Keyword>Type:Condition</cybox:Keyword></cybox:Keywords><cybox:Event id=\\\"Event-BasicEvent-registry-write-SW-Policies-MSoft-system-certs\\\"><cybox:Actions><cybox:Action id=\\\"Action-BasicEvent-registry-write-SW-Policies-MSoft-system-certs\\\"><cybox:Type xsi:type=\\\"cyboxVocabs:ActionTypeVocab-1.0\\\" xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\">Modify</cybox:Type><cybox:Name xsi:type=\\\"cyboxVocabs:ActionNameVocab-1.0\\\" xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\">Modify Registry Key</cybox:Name><cybox:Associated_Objects><cybox:Associated_Object id=\\\"Registry-key-SW-Policies-MSoft-system-certs\\\"><cybox:Properties xsi:type=\\\"WinRegistryKeyObj:WindowsRegistryKeyObjectType\\\" xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\"><ns2:Key pattern_type=\\\"Regex\\\" xmlns:ns2=\\\"http://cybox.mitre.org/objects#WinRegistryKeyObject-2\\\"></ns2:Key></cybox:Properties><cybox:Association_Type xsi:type=\\\"cyboxVocabs:ActionObjectAssociationTypeVocab-1.0\\\" xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\">Affected</cybox:Association_Type></cybox:Associated_Object></cybox:Associated_Objects></cybox:Action></cybox:Actions></cybox:Event></cybox:Observable></cybox:Observables>\"}";
		try {
			String regwritecondRes = HttpClientUtils.composePostRequest(
					"https://" + "10.150.100.243" + ":9090/api/v1/profiles",
					payloadregCond);
			System.out.println(regwritecondRes);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		/*
		 * String ntosSymchk=null; try{ ntosSymchk = sshmngr
		 * .returnCommandOutPut(
		 * "cmd /c cd \"c:\\Program Files\\Debugging Tools for Windows (x64)\" && symchk /v \"c:\\windows\\system32\\ntoskrnl.exe\""
		 * );
		 * 
		 * if (ntosSymchk != null) { if (ntosSymchk
		 * .indexOf("C:\\Windows\\SYMBOLS\\ntkrnlmp.pdb") != -1) {
		 * 
		 * ntosSymchk = ntosSymchk .substring(ntosSymchk
		 * .indexOf("C:\\Windows\\SYMBOLS\\ntkrnlmp.pdb") +
		 * "C:\\Windows\\SYMBOLS\\ntkrnlmp.pdb" .length()); if
		 * (ntosSymchk.indexOf("ntkrnlmp.pdb") != -1) {
		 * 
		 * ntosSymchk = ntosSymchk.substring(0,
		 * ntosSymchk.indexOf("ntkrnlmp.pdb"));
		 * 
		 * }
		 * 
		 * } System.out.println(ntosSymchk);}
		 * 
		 * }catch(Exception e){
		 * 
		 * 
		 * e.printStackTrace(); }
		 */

	}

	public static void main(String[] args) throws Exception {

		/*
		 * VMWareConnector esxiConnector = new VMWareConnector("10.140.63.49");
		 * // poweredOn final VirtualMachine endPointMachine = esxiConnector
		 * .getVirtualMachineByname("win7x64-sym-1");
		 * System.out.println("Memory>>>>" +
		 * endPointMachine.getConfig().hardware.memoryMB);
		 * System.out.println("architecture>>>>" +
		 * endPointMachine.getConfig().getGuestFullName());
		 * System.out.println("tools status >>>"
		 * +endPointMachine.getGuest().toolsRunningStatus); // vm should be on
		 * GuestNicInfo[] d = endPointMachine.getGuest().getNet(); for
		 * (GuestNicInfo dp : d) {
		 * 
		 * System.out.println("Mac Address>>>" + dp.getMacAddress());
		 * System.out.println("Domain name>>>" + dp.dnsConfig.domainName);}
		 */

		/*
		 * System.out.println("Memory>>>" +
		 * VMWareUtils.getVMRamSize("10.140.63.49", "win7x64-sym-1"));
		 * System.out.println("OS Architecture>>>>" +
		 * VMWareUtils.getVMOSArchitecture("10.140.63.49", "win7x64-sym-1"));
		 * System.out.println("Dname>>>" +
		 * VMWareUtils.getVMDomainName("10.140.63.49", "win7x64-sym-1"));
		 * System.out.println("Mac Address>>>" +
		 * VMWareUtils.getVMMacAddress("10.140.63.49", "win7x64-sym-1"));
		 */

		// System.out.println("Driver Version>>>"+Utils.getDriverVersion("s17.dev.countertack.com",
		// "361541ab-104e-2fda-4e8a-fa6f0917cdba"));
		SSHManager ssh=new SSHManager("ramishra", "f00b@r", "10.140.62.61");
		
		ssh.connect();
		ssh.copyFile("C:\\CountertackAutomation", "/home/ramishra/devtools/Test_Scripts/Backend/");
		System.out.println("completed");
//
		/*
		 * String eid = VMWareUtils .performSmokeTerstOnVM("10.140.63.49",
		 * "smoke_snapshot", "win7x64-sym-1", "10.150.100.117", "10.140.63.146",
		 * "user", "password1",
		 * "C:\\Users\\user\\Desktop\\ctagentnew\\CounterTack Agent Installer Hiding.exe"
		 * ); System.out.println("Endpoint id>>>" + eid);
		 */

	}

}
